{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 单分支语句"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](images/2.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-07-21T23:27:26.492097Z",
     "start_time": "2023-07-21T23:27:26.487747Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "abc\n",
      "root\n"
     ]
    }
   ],
   "source": [
    "uid = 0\n",
    "\n",
    "if uid == 0:\n",
    "    print(\"abc\")\n",
    "    \n",
    "print(\"root\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 双分支语句"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](images/3.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-07-21T23:28:47.398034Z",
     "start_time": "2023-07-21T23:28:47.394291Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "abc\n"
     ]
    }
   ],
   "source": [
    "if uid == None:\n",
    "    print(\"root\")\n",
    "else:\n",
    "    print(\"abc\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 多分支语句"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](images/4.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-07-21T23:29:51.523834Z",
     "start_time": "2023-07-21T23:29:51.519021Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Level B\n"
     ]
    }
   ],
   "source": [
    "score = 88.8\n",
    "level = int(score % 10) # 求余数，并向下取整\n",
    "\n",
    "if level >= 10:\n",
    "    print('Level A+')\n",
    "    \n",
    "elif level == 9:\n",
    "    print('Level A')\n",
    "    \n",
    "elif level == 8:\n",
    "    print('Level B')\n",
    "    \n",
    "elif level == 7:\n",
    "    print('Level C')\n",
    "    \n",
    "elif level == 6:\n",
    "    print('Level D')\n",
    "    \n",
    "else:\n",
    "    print('Level E')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 三元条件运算符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-07-21T23:29:59.158031Z",
     "start_time": "2023-07-21T23:29:59.154616Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Level Others\n"
     ]
    }
   ],
   "source": [
    "print('Level A+') if level >= 10 else print('Level Others')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "288px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
